package org.example;

import java.util.HashMap;
import java.util.Map;

public class Test4 {
    //leetcode 1 两数之和 https://leetcode.cn/problems/two-sum/description/
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hash = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (hash.getOrDefault(nums[i],-1) != -1) return new int[]{hash.get(nums[i]),i};
            else hash.put(target - nums[i], i);
        }
        return null;
    }
}
